﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using DDD.Core;

using FloatComparer = DDDTest.Helper.FloatComparer;

namespace DDDTest.Core {
    [TestClass]
    public class TestGraphics3D {

        /// <summary>
        /// 
        /// </summary>
        /// <remarks>
        /// テストの順番によっては値がすでに書き換わっているのでReset()している。
        /// 実質リセットのテスト
        /// </remarks>
        [TestMethod]
        public void Test_New () {
            var g3d = Graphics3D.GetInstance ();
            g3d.Reset ();

            Assert.IsNotNull (g3d);
            Assert.AreEqual (0, g3d.Viewport.X);
            Assert.AreEqual (0, g3d.Viewport.Y);
            Assert.AreEqual (0, g3d.Viewport.Width);
            Assert.AreEqual (0, g3d.Viewport.Height);
            Assert.AreEqual (true, g3d.IsColorClearEnabled);
            Assert.AreEqual (true, g3d.IsDepthClearEnabled);
            Assert.AreEqual (0.0f, g3d.ClearColor.R);
            Assert.AreEqual (0.0f, g3d.ClearColor.G);
            Assert.AreEqual (1.0f, g3d.ClearColor.B);
            Assert.AreEqual (1.0f, g3d.ClearColor.A);
            Assert.AreEqual (1.0f, g3d.ClearDepth);
            Assert.AreEqual (null, g3d.FrameBuffer);
            Assert.AreEqual (null, g3d.NodeSelection);
            Assert.AreEqual (0, g3d.GetRenderPassCount ());

        }

        [TestMethod]
        public void Test_SetViewport () {
            var g3d = Graphics3D.GetInstance ();
            g3d.SetViewort (1, 2, 3, 4);

            Assert.AreEqual (1, g3d.Viewport.X);
            Assert.AreEqual (2, g3d.Viewport.Y);
            Assert.AreEqual (3, g3d.Viewport.Width);
            Assert.AreEqual (4, g3d.Viewport.Height);
        }

        [TestMethod]
        public void Test_SetWorld () {
            var g3d = Graphics3D.GetInstance ();
            var wld = new World ();
            g3d.SetWorld (wld);

            //Assert.AreEqual (wld, g3d.World);
        }

        [TestMethod]
        public void Test_SetFrameBuffer () {
            var g3d = Graphics3D.GetInstance ();
            var fbuf = new FrameBuffer (1, 1, 1);
            g3d.SetFrameBuffer (fbuf);

            Assert.AreEqual (fbuf, g3d.FrameBuffer);
        }

        [TestMethod]
        public void Test_SetRenderPass () {
            var g3d = Graphics3D.GetInstance ();
            g3d.Reset ();

            var sum = 0;
            g3d.RenderPass += delegate {
                sum += 1;
            };
            var delegates = g3d.GetRenderPass ();
            Assert.AreEqual (1, g3d.GetRenderPassCount ());

            foreach (var d in delegates) {
                d.DynamicInvoke ();
            }
            Assert.AreEqual (1, sum);

            g3d.ClearRenderPass ();
            Assert.AreEqual (0, g3d.GetRenderPassCount ());
        }


    }
}
